//
//  WithdrawItemCell.swift
//  d11
//
//  Created by peale on 2018/11/15.
//  Copyright © 2018年 Tech_001. All rights reserved.
//

import UIKit
typealias BankInfoChangeBlock = (_ info: String,_ row:Int) -> Void
class WithdrawItemCell: UITableViewCell {
    var bgImgView : UIImageView?
    var iconImgView : UIImageView?
    var titleLabel : UILabel?
    var textField : UITextField?
    var lineView : UIView?
    var bankInfoChangeBlock: BankInfoChangeBlock?
    func callChangeBlock(_ block: @escaping BankInfoChangeBlock) {
        
        bankInfoChangeBlock = block
    }
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.setUpUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }
    
    func setUpUI() -> Void {
        self.backgroundColor  = UIColor.clear
        self.selectionStyle = UITableViewCell.SelectionStyle.none
        // self.contentView!.backgroundColor  = UIColor.clear
        self.bgImgView = UIImageView.init()
        self.bgImgView?.image = imageNamed("icon_my_cell_item")
        self.bgImgView?.isUserInteractionEnabled = true
        self.contentView.addSubview(bgImgView!);
        self.bgImgView?.snp.makeConstraints{(make) in
            make.width.equalToSuperview().offset(-20)
            make.height.equalTo(60)
            make.centerX.equalTo(self.contentView)
        };
        
        self.lineView = UIView.init()
        self.lineView?.backgroundColor = HexRGBAlpha(0xF3F3F3, 1)
        self.bgImgView?.addSubview(self.lineView!)
        
        self.lineView?.snp.makeConstraints{(make) in
            make.centerX.equalToSuperview()
            make.width.equalToSuperview().offset(-20)
            make.height.equalTo(0.7)
            make.top.equalToSuperview()
        }
        
        self.iconImgView = UIImageView.init()
        self.iconImgView?.image = imageNamed("icon_withdraw_bank_name")
        self.bgImgView?.addSubview(self.iconImgView!)
        self.iconImgView?.snp.makeConstraints{(make) in
            make.left.equalToSuperview().offset(15)
            make.width.equalTo(20)
            make.height.equalTo(20)
            make.centerY.equalTo(self.bgImgView!)
        }
        self.titleLabel = UILabel.init()
        self.titleLabel?.text = "开户姓名"
        self.titleLabel?.textColor = HexRGBAlpha(0x333333, 1)
        self.titleLabel?.font = UIFont.systemFont(ofSize: 15)
        self.titleLabel?.textAlignment = NSTextAlignment.left
        self.bgImgView?.addSubview(self.titleLabel!)
        
        self.titleLabel?.snp.makeConstraints{(make) in
            make.left.equalTo((self.iconImgView?.snp.right)!).offset(15)
            make.width.equalTo(100)
            make.height.equalTo(49)
            make.centerY.equalToSuperview()
        }
        
        
        self.textField = UITextField.init()
        self.textField?.textColor =  HexRGBAlpha(0x8E8F90, 1)
        self.textField?.font = UIFont.systemFont(ofSize: 14)
        self.textField?.textAlignment = NSTextAlignment.right
        self.textField?.placeholder = "请输入开户姓名"
        self.textField?.keyboardType = .asciiCapable
        self.bgImgView?.addSubview(self.textField!)
        self.textField?.addTarget(self, action: #selector(self.actionToChanged(_:)), for: UIControl.Event.editingChanged)
        self.textField?.snp.makeConstraints{(make) in
            make.left.equalTo((self.titleLabel?.snp.right)!).offset(12)
            make.right.equalToSuperview().offset(-15)
            make.centerY.equalToSuperview()
            make.height.equalTo(49)
        }
        
        
    }
    
    func setData(row:Int,value:String?) -> Void {
        self.textField?.text = value
        self.textField?.tag = row
        if row == 0 {
              self.lineView?.isHidden = true
            self.titleLabel?.text = "开户姓名"
            self.textField?.placeholder = "请输入开户姓名"
             self.bgImgView?.image = imageNamed("icon_my_cell_top")
              self.iconImgView?.image = imageNamed("icon_withdraw_bank_username")
             self.textField?.keyboardType = .default
        }else if row == 1 {
            self.lineView?.isHidden = false
            self.titleLabel?.text = "开户账号"
            self.textField?.placeholder = "请输入开户账号"
            self.bgImgView?.image = imageNamed("icon_my_cell_center")
              self.iconImgView?.image = imageNamed("icon_withdraw_bank_number")
              self.textField?.keyboardType = .numberPad
            
        }else if row == 2 {
            self.titleLabel?.text = "开户行地址"
            self.textField?.placeholder = "请输入开户行地址"
            self.bgImgView?.image = imageNamed("icon_my_cell_bottom")
              self.iconImgView?.image = imageNamed("icon_withdraw_address")
             self.lineView?.isHidden = false
              self.textField?.keyboardType = .default
        }
        
    }
    
    @objc func actionToChanged(_ sender: UITextField) -> Void {
        if bankInfoChangeBlock != nil {
            bankInfoChangeBlock!(sender.text!,sender.tag)
        }
    }

}
